package com.bjsxt.service.impl;

import com.bjsxt.pojo.Dept;
import com.bjsxt.pojo.Emp;
import com.bjsxt.service.DeptInsertService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.web.client.RestTemplate;

import java.util.List;

@Service
public class DeptInsertServiceImpl implements DeptInsertService {
    @Autowired
    private RestTemplate restTemplate;
    @Override
    public List<Dept> showDept() {
        List<Dept> list = restTemplate.postForObject("http://dept-selectall/dept/selectAll", null, List.class);
        return list;
    }

    @Override
    public int insert(Emp emp) {
        Integer index = restTemplate.postForObject("http://EMP-INSERT/emp/insert?name={1}&deptId={2}", null, Integer.class,
                emp.getName(), emp.getDeptId());
        return index;
    }

    @Override
    public List<Emp> selectAll() {
        List<Emp> list = restTemplate.postForObject("http://EMP-INSERT/emp/selectAll", null, List.class);
        return list;
    }

    @Override
    public Dept selectBydeptId(Integer deptId) {
        Dept dept = restTemplate.postForObject("http://dept-selectall/dept/selectAll?deptId={1}", null, Dept.class,deptId);
        return dept;
    }
}
